import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeContent from '../views/home/HomeContent.vue'
import HomeAside from '../views/home/HomeAside.vue'
import tools from '@/tools'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    components: {
      main: HomeContent,
      aside: HomeAside
    },
    children: [{
      path: '/hot/:id',
      name: "hot",
      component: () => import(/* webpackChunkName: "home" */ '../views/home/Hot.vue')
    }],
    meta: {
      isKeep: true
    }
  },
  {
    path: '/qa',
    name: 'qa',
    components: {
      main: () => import(/* webpackChunkName: "qa" */ '../views/qa/QaContent.vue'),
      aside: () => import(/* webpackChunkName: "qa" */ '../views/qa/QaAside.vue')
    },
    meta: {
      isKeep: true
    }
  },
  {
    path: '/test',
    name: 'test',
    components:{
      main: () => import(/* webpackChunkName: "test" */ '../views/test.vue')
    } 
  },
  {
    path: '/about',
    name: 'about',
    components:{
      main: () => import(/* webpackChunkName: "test" */ '../views/AboutView.vue')
    } 
  },
  {
    path: '/collection',
    name: 'collection',
    components:{
      main: () => import(/* webpackChunkName: "user" */ '../views/user/collection.vue')
    },
    beforeEnter(to, from, next){
      if(to.path === "/login" || tools.getCookie("isLogin") === "ok"){
        next();
      }else{
        next("/login")
      }
    }
  },
  {
    path: "/message",
    name: "message",
    components:{
      main: () => import(/* webpackChunkName: "user" */ '../views/user/message.vue')
    }
  },
  {
    path: "/login",
    name: "login",
    components:{
      main: () => import(/* webpackChunkName: "login" */ '../views/user/login.vue')
    }
  }
]

const router = new VueRouter({
  routes
})

export default router
